package com.dic.mall.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @author ：leeliang
 * @date ：Created in 2020/7/18 0:49
 * @description：浏览器跨域请求过滤器
 * @modified By：
 * @version: 1.0
 */
@Configuration
public class MyCrosFilter {

    @Bean
    public CorsWebFilter crosWebFilter(){
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedHeader("*");
        config.addAllowedOrigin("*");
        config.addAllowedMethod("*");
        config.setAllowCredentials(true);

        source.registerCorsConfiguration("/**",config);
         CorsWebFilter corsWebFilter = new CorsWebFilter(source);
         return corsWebFilter;
    }




}
